package com.jml.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

public class ChanelApiOpen {

	public static void main(String[] args) throws Exception {
		//第一个是代表文件路径，第二个是针对文件的操作
		FileChannel inChanner = FileChannel.open(Paths.get("1.jpg"),StandardOpenOption.READ);
		FileChannel outChanner = FileChannel.open(Paths.get("3.jpg"),StandardOpenOption.WRITE,StandardOpenOption.READ,StandardOpenOption.CREATE_NEW);
		//只读模式，从0开始到通道的全部
		MappedByteBuffer inMappedBuff = inChanner.map(FileChannel.MapMode.READ_ONLY,0,inChanner.size());
		MappedByteBuffer outMappedBuff = outChanner.map(FileChannel.MapMode.READ_WRITE,0,inChanner.size());
		//直接对缓冲区进行数据读写操作
		byte[] bst =new byte[inMappedBuff.limit()];
		inMappedBuff.get(bst);
		outMappedBuff.put(bst);
		inChanner.close();
		outChanner.close();
	}

}
